import httplib2
import urllib

http = httplib2.Http()

def get_cookie(login_url='http://hi5.com/friend/login.do'):
  login_params = urllib.urlencode({
	  'email' : 'wearetherock@hotmail.com',
	  'password' : "xxx"
	  })
	  
  headers = {'Content-type': 'application/x-www-form-urlencoded'} 
  response, content = http.request(login_url, method='POST', body=login_params, headers=headers)
  return response['set-cookie']
  
def comment(comment_url, message):
  import Cookie
  c = Cookie.SimpleCookie()
  
  hi5_cookie = get_cookie()
  c.load(hi5_cookie)
  js_session =  c['JSESSIONID'].value
  comment_params = urllib.urlencode({
	  'userId': '157658571',
	  'userid':'157658571',
	    "timestamp" : "",
	    "js" : js_session ,
	    'body' : message
  })
  headers = {'Content-type': 'application/x-www-form-urlencoded'} 
  response, content = http.request(comment_url, method='POST', body = comment_params, headers=headers)
  return response, content

comment_url = 'http://www.hi5.com/friend/profile/signBook.do?userid=157658571'
response, content = comment(comment_url, ' wearetherock' )

print response
